<template>
    <div class="goods-list">
        <!-- 基本版 -->
        <div class="goods-item" @click="goDetail(1)">
            <img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=391349527,3608422125&fm=27&gp=0.jpg" alt="">
            <h3 class="title">华为荣的数据金风科技水电费二维无额外付费无法二维无无无无无无无无无巍峨鹅鹅鹅鹅鹅鹅</h3>
            <div class="info">
                <p class="price">
                    <span class="new">￥899</span>
                    <span class="old">￥999</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩60件</span>
                </p>
            </div>
        </div>
        <mt-button type="danger" size="large">加载更多</mt-button>

        <!-- 渲染版,编程式导航 -->
        <!-- <div class="goods-item" v-for="item in goodslist" :key="item.index" @click="goDetail(item.id)">
            <img :src="item.img_url" alt="">
            <h3 class="title">{{ item.title }}</h3>
            <div class="info">
                <p class="price">
                    <span class="new">￥{{ item.sell_price }}</span>
                    <span class="old">￥{{ item.market_price }}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{ item.stock_quantity }}件</span>
                </p>
            </div>
        </div>
         <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
        -->

    </div>
</template>
<script>
    export default {
        //私有数据
        data(){
            return {
                pageindex: 1,  //默认显示第一列数据
                goodslist: []  //把全部商品列表数据挂载
            }
        },
        created(){
            this.getGoodsList();
        },
        methods: {
            //的到商品列表方法
            getGoodsList(){
                this.$http.get("/api/getgoods?pageindex="+this.pageindex).then(result=>{
                    if(result.body.status === 0){
                        //每次进行一次拼接，防止之前的列表数据看不到
                        this.goodslist = this.goodslist.concat(result.body.message);
                    }
                })
            },
            //点击加载更多
            getMore(){
                this.pageindex++,
                this.getGoodsList()
            },
            //编程式导航跳转页面
            goDetail(id){
                //$router用法,也是vue实例的一个属性
                //1.最简单的
                // this.$router.push("/home/goodsinfo/"+id)
                // //2.通过对象路劲
                // this.$router.push({path: "/home/goodsinfo" + id})
                //3.通过在路由的命名,
                this.$router.push({ name: "goodsinfo", params: { id } });
            }
        }
    }
</script>
<style lang="scss" scoped>
    .goods-list {
        padding: 7px;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        .goods-item {
           width: 49%;
           border: 1px solid #ccc;
           box-shadow: 0 0 8px #ccc;
           margin: 3px 0;
           padding: 2px; 
           /*主要解决标题文字长短带来的问题，侧轴对其*/
           display: flex;
           flex-direction: column;
            justify-content: space-between;
            min-height: 238px;
            img {
               width: 100%;
            }
            .title{
              font-size: 14px;
              margin: 0;
            }
            .info {
                background-color: #eee;
                p{
                    padding: 0  5px ;
                    margin: 0;
                }
                .price {
                    .new {
                       font-weight: bold;
                        font-size: 16px;
                        color: red;
                    }
                    .old {
                        text-decoration: line-through;
                        margin-left: 10px
                    }
                }
                .sell {
                    display: flex;
                    justify-content: space-between;
                    font-size: 13px;
                }

            }
        }
    }
</style>
